What is recursion in Java also explain it, and write code for reverse string using recursion technique?
home / developersection / forums / what is recursion in java and also write code for reverse string?
What is recursion in Java also explain it, and write code for reverse string using recursion technique?
Krishnapriya Rajeev
21-Mar-2023Recursion is the process in which a function calls itself directly or indirectly and the corresponding functions are called recursive functions.
Recursive function or method calls store new parameters and local variables on the stack, which are then removed as we return from the recursive calls. While recursive functions enable us to develop simple and clear solutions for certain problems easily, they can also lead to slow execution due to added overhead and additional function calls.
The concept of recursive function can be used to find the factorial of a number as shown below:
Here, if factorial() is called with an argument of 1, then it returns 1 else it returns the product of n*factorial(n-1).
Code for reversing string using recursion in java
Sanjay Goenka
06-Mar-2023I have no idea about the theory parts.
I try to write code for a reverse string in recursion.
Output →
5-saj1-wu-sakfhjdsa-afsdfhjk
I hope you enjoy this answer. Bye !!!
Amrita Bhattacharjee
08-Feb-2023Recusion is a method where a function calls directly itself. In java, recursion is recognised as a process where any particular function calls itself. This process is used for avoiding difficult problems by making them comparatively easier. This method is used rarely and when any complicated type of code is needed to write then this process is used to make that simple. It is the process where the items are repeated in a same kind of manner.
The code for reverse string using recursion will be as follows: